package com.ymatou.iapi.deviceid.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.deviceid.parameter.GetUserIdListBean;
import com.ymatou.iapi.deviceid.parameter.SaveBean;
import com.ymatou.iapi.deviceid.service.GetUserIdListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DeviceidCallService;
/**
*根据设备号获取用户列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserIdList{
	private static GetUserIdListBean getuseridlistBean;
	private static GetUserIdListCall getuseridlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据设备号获取用户列表");
	}

	@Before
	public void caseUp() {
		getuseridlistBean=new GetUserIdListBean();
		getuseridlistCall=new GetUserIdListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuseridlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_001() {
		Logger.start(true,"根据设备号获取用户列表");
		try {
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);
			
			SaveBean saveBean1= DeviceidCallService.setDefaultFullSaveBean();
			saveBean1.setDeviceid(saveBean.getDeviceid());
			DeviceidCallService.saveCall(saveBean1);

			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(0);
			getuseridlistBean.setLimit(10);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("0", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(saveBean.getDeviceid() + " exists", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyEquals(saveBean.getUserid(), results.get(0), "验证返回data");
			Logger.verifyEquals(saveBean1.getUserid(), results.get(1), "验证返回data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_002() {
		Logger.start(true,"根据设备号获取用户列表-返回按照激活时间 ASC 排序");
		try {
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);
			
			SaveBean saveBean1= DeviceidCallService.setDefaultFullSaveBean();
			saveBean1.setDeviceid(saveBean.getDeviceid());
			DeviceidCallService.saveCall(saveBean1);

			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(1);
			getuseridlistBean.setLimit(10);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("0", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(saveBean.getDeviceid() + " exists", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyEquals(saveBean1.getUserid(), results.get(0), "验证返回data");
			Logger.verifyEquals(saveBean.getUserid(), results.get(1), "验证返回data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_003() {
		Logger.start(true,"根据设备号获取用户列表-返回按照激活时间 DESC 排序");
		try {
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);
			
			SaveBean saveBean1= DeviceidCallService.setDefaultFullSaveBean();
			saveBean1.setDeviceid(saveBean.getDeviceid());
			DeviceidCallService.saveCall(saveBean1);

			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(0);
			getuseridlistBean.setLimit(10);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("0", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(saveBean.getDeviceid() + " exists", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyEquals(saveBean.getUserid(), results.get(0), "验证返回data");
			Logger.verifyEquals(saveBean1.getUserid(), results.get(1), "验证返回data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_004() {
		Logger.start(true,"根据设备号获取用户列表-deviceId空");
		try {
			getuseridlistBean.setType(0);
			getuseridlistBean.setLimit(10);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("100", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals("deviceId不能为空", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyIsNull(results, "验证返回data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_005() {
		Logger.start(true,"根据设备号获取用户列表-type取非法值");
		try {
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);

			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(3);
			getuseridlistBean.setLimit(10);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("100", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals("type必须是0或者1", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyIsNull(results, "验证返回data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_006() {
		Logger.start(true,"根据设备号获取用户列表-limit小于0");
		try {
			
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);

			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(1);
			getuseridlistBean.setLimit(-10);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("100", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals("limit必须是1到20之间的数", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyIsNull(results, "验证返回data");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_007() {
		Logger.start(true,"根据设备号获取用户列表-limit大于20");
		try {
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);

			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(1);
			getuseridlistBean.setLimit(40);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("100", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals("limit必须是1到20之间的数", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyIsNull(results, "验证返回data");					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_008() {
		Logger.start(true,"根据设备号获取用户列表-limit起作用");
		try {
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);
			
			SaveBean saveBean1= DeviceidCallService.setDefaultFullSaveBean();
			saveBean1.setDeviceid(saveBean.getDeviceid());
			DeviceidCallService.saveCall(saveBean1);

			SaveBean saveBean2= DeviceidCallService.setDefaultFullSaveBean();
			saveBean2.setDeviceid(saveBean.getDeviceid());
			DeviceidCallService.saveCall(saveBean2);
			
			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(0);
			getuseridlistBean.setLimit(2);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("0", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(saveBean.getDeviceid() + " exists", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();
			
			Logger.verifyEquals(2, results.size(), "验证返回data");
			
			Logger.verifyEquals(saveBean.getUserid(), results.get(0), "验证返回data");
			Logger.verifyEquals(saveBean1.getUserid(), results.get(1), "验证返回data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserIdList_009() {
		Logger.start(true,"根据设备号获取用户列表-相同的");
		try {
			SaveBean saveBean = DeviceidCallService.setDefaultFullSaveBean();
			DeviceidCallService.saveCall(saveBean);
			
			SaveBean saveBean1= DeviceidCallService.setDefaultFullSaveBean();
			saveBean1.setDeviceid(saveBean.getDeviceid());
			saveBean1.setUserid(saveBean.getUserid());
			DeviceidCallService.saveCall(saveBean1);

			getuseridlistBean.setDeviceId(saveBean.getDeviceid());
			getuseridlistBean.setType(0);
			getuseridlistBean.setLimit(10);
			
			getuseridlistCall.setData(getuseridlistBean);
			getuseridlistCall.callService();	
			
			Logger.verifyEquals("0", getuseridlistCall.getCode(), "验证返回Code");
			Logger.verifyEquals("0", getuseridlistCall.getBCode(), "验证返回BCode");
			Logger.verifyEquals(saveBean.getDeviceid() + " exists", getuseridlistCall.getMSG(), "验证返回Message");

			List<Integer> results = getuseridlistCall.getUserList().getData();

			Logger.verifyEquals(1, results.size(), "验证返回data");
			
			Logger.verifyEquals(saveBean.getUserid(), results.get(0), "验证返回data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}